package org.raymond.iworks.study.basic.designpattern.state;

import java.util.Random;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 * 可以抽奖的状态
 */
public class CanRaffleState implements State{
    private RaffleActivity activity;
    public CanRaffleState(RaffleActivity activity){
        this.activity = activity;
    }
    @Override
    public void deduceMoney() {
        System.out.println("已经扣过积分了");
    }

    @Override
    public boolean raffle() {
        System.out.println("正在抽奖,请稍等");
        Random r = new Random();
        int num = r.nextInt(10);
        // 10%中奖机会
        if(num==0){
            activity.setState(activity.getDispenseState());
            return true;
        }else {
            System.out.println("很遗憾,没有中奖");
            activity.setState(activity.getNoRaffleState());
            return false;
        }
    }

    @Override
    public void dispensePrize() {
        System.out.println("没中奖,不能发放奖品");
    }
}
